const CryptoJS = require("crypto-js");
const crypto = require("crypto");

//key的字符串要超過16個，iv要超過6個。否則解密出來為空
export const SECRET_KEY = CryptoJS.enc.Utf8.parse("compeq12345678900123");
export const SECRET_IV = CryptoJS.enc.Utf8.parse("99999999123");

export const encrypt = (password: string) => {
  return crypto.createHash("md5").update(password).digest("hex");
};

export const decrypt = (password: any) => {
  // password = (password+'').replace(/\n*$/g,'').replace(/\n/g,'');
  const turePwddecrypt = CryptoJS.AES.decrypt(password, SECRET_KEY, {
    iv: SECRET_IV,
    mode: CryptoJS.mode.CBC,
    padding: CryptoJS.pad.Pkcs7,
  });
  return CryptoJS.enc.Utf8.stringify(turePwddecrypt);
};
